local cihuang = fk.CreateSkill{
    name = "va_heg__cihuang_manoeuvre",
}

Fk:loadTranslationTable{
    ["va_heg__cihuang_manoeuvre"] = "雌黄⇋",
    [":va_heg__cihuang_manoeuvre"] = "出牌阶段限一次，你可以选择一名其他角色进行拼点。若你赢，则你视为对其使用一张基本牌。",

    ["#va_heg__cihuang_manoeuvre"] = "雌黄⇋：你可以选择一名其他角色进行拼点",
    ["#va_heg__cihuang_mn_use"] = "雌黄⇋：视为对%dest使用一张基本牌",
}

local U = require "packages/utility/utility"

cihuang:addEffect("active",{
    anim_type = "special",
    prompt = "#va_heg__cihuang_manoeuvre",
    can_use = function (self, player)
        return player:usedSkillTimes(cihuang.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    end,
    card_num = 0,
    target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function (self, player, to_select, selected)
        return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
    end,
    on_use = function (self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local pindian = player:pindian({target}, cihuang.name)
        if player.dead or target.dead then return end
        if pindian.results[target].winner == player then
            local all_names = Fk:getAllCardNames("b", false)
            local names = {}
            for _, n in ipairs(all_names) do
                local card = Fk:cloneCard(n)
                if player:canUseTo(card, target) then
                    table.insert(names, n)
                end
            end
        if #names == 0 then return end
        local name = U.askForChooseCardNames(room, player, names, 1, 1, cihuang.name, "#va_heg__cihuang_mn_use::"..target.id, all_names)
        if name then
            room:useVirtualCard(name[1], nil, player, target, cihuang.name, false)
        end
      end
    end
})

cihuang:addEffect(fk.TurnEnd, {
  late_refresh = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("va_heg__cihuang_manoeuvre", true, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-va_heg__cihuang_manoeuvre", nil)
    room:setPlayerMark(player, "@@va_heg__cihuang_manoeuvre", 0)
  end,
})

return cihuang